/** COPYRIGHT(C) 2008. Loc Phan. All Rights Reserved.
    A class that calculate power
    @author Loc Phan
    @version 1.01 2008-11-20
*/

package edu.sjsu.cs.phan;

public class Numeric
{
   /**If n is negative, returns 1/(x^-n)
    * if n is positive and even, returns x^n
    * if n is positive and off, returns x^n-1
    * @param x Number
    * @param n To the power
    * @return power
    */
   public static double intPower(double x, int n)
   {
      int determine = n % 2;
      if(n<0)
      {
         return (1/(Math.pow(x, -n)));
      }
      else if(n>0&&determine==0)
      {
         return Math.pow(x,n);
      }
      else
      {
         return Math.pow(x, n-1);
      }
   }
}
